package com.citywy.controller;

import com.citywy.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

@Controller
@RequestMapping("/seco")
@SessionAttributes(value = {"uname","upwd"},types = {Integer.class})
public class SessionAttributeController {

    /**
     * 数据存入SessionAttribute
     * @param model
     * @return
     * model是spring提供的一个接口，该接口有一个实现类ExtendedModelMap
     * 该类继承了ModelMap,而ModelMap就是LinkedHashMap子类
     */
    @RequestMapping("testPut")
    public String testPut(Model model){
        model.addAttribute("uname","泰勒");
        model.addAttribute("upwd","123456");
        model.addAttribute("age",12);
        //跳转之前将数据保存到uname、upwd和age中，因为注解@SessionAttribute中有这几个参数
        return "pages/success";
    }


    @RequestMapping("testGet")
    public String testGet(ModelMap model){
        System.out.println(model.get("uname")+"--"+model.get("upwd")+"--"+model.get("age"));
        return "pages/success";
    }

    @RequestMapping("testClean")
    public String complete(SessionStatus sessionStatus){
        sessionStatus.setComplete();
        return "pages/success";
    }
}
